// JavaScript Document

dialog_ids = new Array();


function show_dialog(id, left, top, right)
{
	dialog_ids.push(id);
	try
	{
		if(top >= 0)
		{
			window[id + "_top"] = top;
			window[id + "_left"] = left;
			window[id + "_right"] = right;
		}
	}
	catch(err)
	{
	}
	inner_update_postion();
	$("#"+id).show();
	
}

function close_dialog(id)
{
	for (index = dialog_ids.length - 1; index >=0; index--)
    {
		if(id == dialog_ids[index])
		{
			dialog_ids[index] = "";
		}
	}
	$("#"+id).hide();
}



function update_postion()
{
setTimeout(inner_update_postion, 10);
}

function inner_update_postion()
{	var window_width = $(window).width();
	var window_height = $(window).height();
	for (id in dialog_ids)
    {
		try
		{
			e = $("#" + dialog_ids[id]);
			if(window[dialog_ids[id] + "_top"])
			{
				if(window[dialog_ids[id] + "_top"] >= 0)
				{
					e.css("top", window[dialog_ids[id] + "_top"]  + $(window).scrollTop());
				}
				if(window[dialog_ids[id] + "_left"] >= 0)
				{
					e.css("left", window[dialog_ids[id] + "_left"]);
				}
				
				if(window[dialog_ids[id] + "_right"] >= 0)
				{
					e.css("right", window[dialog_ids[id] + "_right"]);
				}
			}
			else
			{
				var width = e.width();
				var height = e.height();
			
				$("#debug_text").text("" + width + ":" + height + ":" + window_width + ":" + window_height + ":" + $(window).scrollTop());
				
				if(window_height > height)
				{
					var e_top = Math.floor((window_height - height) /2 );
				}
				else
				{
					var e_top = 10;
				}
				
				if(window_width > width)
				{
					var e_right = Math.floor((window_width - width) /2 );
				}
				else
				{
					var e_right = 10;
				}
				e.css("top", e_top + $(window).scrollTop());
				e.css("right", e_right);
			}
		}
		catch(err)
		{
		}
	}
}
$(document).ready(function(){$(window).scroll(update_postion).resize(update_postion);});